﻿// KittyFeral PVE - HB Routine for FeralDruid 5.4 - By Neyia
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Action = Styx.TreeSharp.Action;

namespace KittyFeral
{
    public partial class Main : CombatRoutine
    {
        public int ECLIPSE_DIRECTION;

        Composite BoomkinRotation()
        {
            return 
                new PrioritySelector(
                new Decorator(ret => gotTarget && !Me.IsSafelyFacing(Me.CurrentTarget), new Action(delegate { Me.CurrentTarget.Face(); return RunStatus.Failure; })),
                Cast(MOONKIN_FORM, ret => Me.Shapeshift != ShapeshiftForm.Moonkin),
                Cast(HEALING_TOUCH, ret => Me.HealthPercent <= 65),
                Cast(REJUVENATION, ret => Me.HealthPercent <= 85 && !buffExists(REJUVENATION, Me)),
                Cast(FAERIE_FIRE, ret => gotTarget
                    && SpellManager.HasSpell(FAERIE_FIRE)
                    && !SpellManager.HasSpell(FAERIE_SWARM)
                    && !spellOnCooldown(FAERIE_FIRE)
                    && (!debuffExists(WEAKENED_ARMOR, Me.CurrentTarget) || !debuffExists(FAERIE_FIRE, Me.CurrentTarget))
                    && Me.CurrentTarget.Distance <= 35),
                Cast(FAERIE_SWARM, ret => gotTarget
                    && !SpellManager.HasSpell(FAERIE_SWARM)
                    && !spellOnCooldown(FAERIE_FIRE)
                    && (!debuffExists(WEAKENED_ARMOR, Me.CurrentTarget) || !debuffExists(FAERIE_SWARM, Me.CurrentTarget))
                    && Me.CurrentTarget.Distance <= 35),
                Cast(STARSURGE, ret => gotTarget && IsOverlayed(STARSURGE) && Me.CurrentTarget.Distance <= 35),
                Cast(MOONFIREB, ret => gotTarget && IsOverlayed(MOONFIREB) && !debuffExists(MOONFIREB, Me.CurrentTarget) && Me.CurrentTarget.Distance <= 35),
                Cast(SUNFIRE, ret => gotTarget && IsOverlayed(SUNFIRE) && !debuffExists(SUNFIRE, Me.CurrentTarget) && Me.CurrentTarget.Distance <= 35),
                Cast(MOONFIREB, ret => gotTarget && !IsOverlayed(SUNFIRE) && !IsOverlayed(MOONFIREB) && !debuffExists(MOONFIREB, Me.CurrentTarget) && Me.CurrentTarget.Distance <= 35),
                Cast(SUNFIRE, ret => gotTarget && !IsOverlayed(SUNFIRE) && !IsOverlayed(MOONFIREB) && !debuffExists(SUNFIRE, Me.CurrentTarget) && Me.CurrentTarget.Distance <= 35),
                Cast(INCARNATIONB, ret => gotTarget && isBoss && !spellOnCooldown(INCARNATIONB) && Eclipse() == 1 && IsOverlayed(STARFIRE) && Me.CurrentTarget.Distance <= 35),
                Cast(NATURES_VIGIL, ret => gotTarget && isBoss && !spellOnCooldown(NATURES_VIGIL) && Eclipse() == 1 && IsOverlayed(STARFIRE) && Me.CurrentTarget.Distance <= 35),
                new Decorator(ret => gotTarget && !spellOnCooldown(URSOLS_VORTEX) && addCount >= 3 && Me.CurrentTarget.Distance <= 35, Vortex()),
                Cast(STARFALL, ret => gotTarget && SpellManager.HasSpell(STARFALL) && !spellOnCooldown(STARFALL) && Me.CurrentTarget.Distance <= 35),
                Cast(CELESTIAL_ALIGNEMENT, ret => gotTarget && !spellOnCooldown(CELESTIAL_ALIGNEMENT) && Eclipse() == 1 && IsOverlayed(STARFIRE) && Me.CurrentTarget.Distance <= 35),
                Cast(STARFIRE, ret => gotTarget && Eclipse() == 1 && Me.CurrentTarget.Distance <= 35),
                Cast(WRATHB, ret => gotTarget && Me.CurrentTarget.Distance <= 35)
                );
        }
        #region overlayed
        public bool IsOverlayed(int spellID)
        {
            return Lua.GetReturnVal<bool>("return IsSpellOverlayed(" + spellID + ")", 0);
        }
        #endregion overlayed

        #region eclipse
        public int Eclipse()
        {
            
            var DIRECTION = Lua.GetReturnVal<String>(String.Format("return GetEclipseDirection()"), 0);
            if (DIRECTION == "moon") { return ECLIPSE_DIRECTION = -1; }
            if (DIRECTION == "sun") { return ECLIPSE_DIRECTION = 1; }
            return ECLIPSE_DIRECTION = 0;
        }
        #endregion

        #region spellId's
        public int MOONFIREB = 8921;
        public int WRATHB = 5176;
        public int STARSURGE = 78674;
        public int STARFIRE = 2912;
        public int SUNFIRE = 93402;
        public int ECLIPSE_SOLAR = 48517;
        public int ECLIPSE_LUNAR = 48518;
        public int NATURES_VIGIL = 124974;
        public int ASTRAL_COMMUNION = 127663;
        public int MOONKIN_FORM = 24858;
        public int STARFALL = 48505;
        public int CELESTIAL_ALIGNEMENT = 112071;
        public int INCARNATIONB = 102560;
        public int URSOLS_VORTEX = 102793;
        #endregion

        Composite AstralCommunion()
        {
            return new Action(ret =>
            {
                if (Eclipse() != 1 && SpellManager.CanCast(ASTRAL_COMMUNION))
                {
                    SpellManager.Cast(ASTRAL_COMMUNION);
                    lastCast = ASTRAL_COMMUNION;
                }
                return RunStatus.Failure;
            });
        }

        Composite Vortex()
        {
            return new Action(ret =>
            {
                if (SpellManager.CanCast(URSOLS_VORTEX))
                {
                    SpellManager.Cast(URSOLS_VORTEX);
                    SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
                    lastCast = URSOLS_VORTEX;
                }
                return RunStatus.Failure;
            });
        }
    }
}
